<?php
/**
 * Object Relational Persistence Mapping Class for table: package_test_item
 *
 * @package	com.athena
 * @author	LHV
 */
class PackageTestItem extends ORDataObject {

	/**#@+
	 * Fields of table: package_test_item mapped to class members
	 */
	var $package_item_id		= '';
	var $test_id		= '';
	/**#@-*/


	/**
	 * DB Table
	 */
	var $_table = 'package_test_item';

	/**
	 * Primary Key
	 */
	var $_key = 'package_item_id';
	
	/**
	 * Internal Name
	 */
	var $_internalName = 'PackageTestItem';

	/**
	 * Handle instantiation
	 */
	function PackageTestItem() {
		parent::ORDataObject();
	}

	public function delete($packageItemId) {
		$testItemService = Celini::newORDO('PackageTestAssoService');
		$testItemService->delete($packageItemId);
		
		$sql = "delete from $this->_table where package_item_id = $packageItemId";
		$this->_execute($sql);
	}
	
	public function addItem($packageItemId, $testId, $testItem) {
		$data = array (
			'package_item_id'	=> $packageItemId,
			'test_id'		=> $testId);
		$this->populateArray($data);
		$this->persist();

		$asso = Celini::newORDO('PackageTestAssoService');
		$asso->addItem($packageItemId, $testItem);
	}
	
	public function getAllServiceOfTest($packageTestItemId) {
		$ds = new Datasource_sql();
		$sql = array(
			'cols' 		=> "ASSO.service_id",
			'from' 		=> "package_test_item PI
						INNER JOIN package_test_asso_service ASSO ON PI.package_item_id = ASSO.package_item_id",
			'where' 	=> "PI.package_item_id = $packageTestItemId", 						
			);
					
		$ds->setup($this->_db,$sql);
		return $ds->toArray('service_id');
	}
}
?>
